// 面试题 17.08. 马戏团人塔

import {search} from '../util/Util'

function bestSeqAtIndex(height: number[], weight: number[]): number {
    interface Pair{
        h:number,
        w:number
    }

    let pairs:Pair[] = []

    for(let i=0;i<height.length;i++){
        pairs.push({
            h:height[i],
            w:weight[i]
        })
    }

    pairs.sort((a,b)=>{
        if(a.h!=b.h) return a.h - b.h
        return b.w-a.w 
    })
    
    let seq:number[] = []

    for(let i=0;i<pairs.length;i++){
        const k = pairs[i].w
        let index = search(seq,k)
        if(index<0) index = -index-1
        if(index==seq.length) seq.push(k)
        else seq[index] = k
    }
    return seq.length
};

console.log(bestSeqAtIndex([65,70,56,75,60,68],
    [100,150,90,190,95,110]))

